package com.hzw.saas.web.app.user.controller;

import java.util.List;

import com.hzw.saas.api.user.ICustomerLevelService;
import com.hzw.saas.api.user.IUserRightsService;
import com.hzw.saas.api.user.bo.CustomerLevelExpireBO;
import com.hzw.saas.api.user.bo.UserRightsBO;
import com.hzw.saas.common.config.annotation.SysLog;
import com.hzw.saas.common.security.pojo.dto.SaasUser;
import com.hzw.saas.common.security.utils.SecurityUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import lombok.RequiredArgsConstructor;

/**
 * 用户权益 Controller
 *
 * @author zzl
 * @since 05/25/2021
 */
@Controller
@RequestMapping("/user")
@RequiredArgsConstructor
@Api(tags = "用户中心/用户权益")
@Validated
public class UserRightsController {

    private final ICustomerLevelService customerLevelService;
    private final IUserRightsService userRightsService;

    @GetMapping("/levels")
    @SysLog(operation = "获取权益级别列表", mode = 1)
    @ApiOperation(value = "获取权益级别列表", notes = "获取权益级别列表")
    @ApiOperationSort(1)
    public ResponseEntity<List<CustomerLevelExpireBO>> ListCustomerLevel() {
        List<CustomerLevelExpireBO> resultList = customerLevelService.listLevelsWithExpireTime();
        return ResponseEntity.ok(resultList);
    }

    @GetMapping("/rights")
    @SysLog(operation = "获取用户权益信息", mode = 1)
    @ApiOperation(value = "获取用户权益信息", notes = "获取用户权益信息")
    @ApiOperationSort(2)
    public ResponseEntity<UserRightsBO> getUserRights() {
        SaasUser user = SecurityUtils.getUser();
        UserRightsBO userRights = userRightsService.getUserRightsByUser(user.getUserId());
        return ResponseEntity.ok(userRights);
    }

}
